import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

//全局访问的state对象
const state = {
    //设置的初始属性值
    //账套
    accountSet: {
        id: '', //账套id
        accuracy: 6, //本位币精度,小数位数 写死传6
        beginPer: '', //当前会计期间, 接口查询
        setBookId: "",
        companyId: '', //公司ID 接口查询数据
        companyName: '', //公司名称  接口查询数据
        currency: 'CNY', //本位币代码，默认CNY  接口查询数据
        description: '', //账套名称
        period: '12', //会计期间,默认传12
        status: 0 //状态：0新增 1 启用 2冻结
    },
    userData: {
        id: "",
        username: "",
        userNumber: "",
        account: null,
        mobile: null,
        createtime: null,
        updatetime: null,
        score: null,
        email: null,
        level: null,
    },
    token_mark: '',
    // 菜单
    //模块
    navList: [],
    //菜单
    menuData: {
        menu: {},
        index: 1
    },
    //最后一次路由
    lastRouter: '',
    //权限树
    loadApply:[]
   
}

//实时监听state值的变化(最新状态)
const getters = {
    //state
    getUser(state) {
        return state.userData
    },

    getAccountSet(state) {
        return state.accountSet
    },
    getToken(state) {
        return state.token_mark
    },
    getNavList(state) {
        return state.navList
    },
    getMenu(state) {
        return state.menuData
    },
    getLastRouter(state) {
        return state.lastRouter
    },
    getLoadApply(state) {
        return state.loadApply
    },
}

//修改store中的值
const mutations = {
    changeUser(state, val) {
        state.userData = val
    },
    changeAccountSet(state, newName) {
        state.accountSet = newName
    },
    changeToken(state, newName) {
        state.token_mark = newName
    },
    changeNavList(state, newName) {
        state.navList = newName
    },
    changeMenu(state, newName) {
        state.menuData = newName
    },
    changeLastRouter(state, newName) {
        state.lastRouter = newName
    },
    changeLoadApply(state, newName) {
        state.loadApply = newName
    },
    resetStore(state, val) {
        state = {
            //设置的初始属性值
            //账套
            accountSet: {
                id: '', //账套id
                accuracy: 6, //本位币精度,小数位数 写死传6
                beginPer: '', //当前会计期间, 接口查询
                companyId: '', //公司ID 接口查询数据
                companyName: '', //公司名称  接口查询数据
                currency: 'CNY', //本位币代码，默认CNY  接口查询数据
                description: '', //账套名称
                period: '12', //会计期间,默认传12
                status: 0 //状态：0新增 1 启用 2冻结
            },
            userData: {
                id: "",
                username: "",
                userNumber: "",
                account: null,
                mobile: null,
                createtime: null,
                updatetime: null,
                score: null,
                email: null,
                level: null,
            },
            token_mark: '',
            // 菜单

            //模块
            navList: [],
            //菜单
            menuData: {
                menu: {},
                index: 0
            },
            lastRouter: '/',
            loadApply:[]
        }
    }
}




export default new Vuex.Store({
    state,
    mutations,
    getters
})